<?php

namespace App\Admin\Extensions\Grid;

use Encore\Admin\Admin;
use Encore\Admin\Grid\Displayers\AbstractDisplayer;
use Illuminate\Support\Facades\Storage;
use Illuminate\Contracts\Support\Arrayable;

class GridExpand extends AbstractDisplayer
{
    public function display($id = '')
    {
        Admin::script("$('.grid-expand').on('click', function () {
    if ($(this).data('inserted') == '0') {
        var key = $(this).data('key');
        var row = $(this).closest('tr');
        var html = $('template.grid-expand-'+key).html();

        row.after(\"<tr><td colspan='\"+row.find('td').length+\"' style='padding:0 !important; border:0px;'>\"+html+\"\");

        $(this).data('inserted', 1);
    }

    $(\"i\", this).toggleClass(\"fa-caret-right fa-caret-down\");
});");

            return <<<EOT
        <a class="btn btn-xs btn-default grid-expand collapsed" data-inserted="0" data-key="$id" data-toggle="collapse" data-target="#grid-collapse-$id" aria-expanded="false">
           <i class="fa fa-caret-right"></i> {$this->value}
        </a>
        <template class="grid-expand-$id">
        <div id="grid-collapse-$id" class="collapse">
        <table class="table">
        <thead><tr></tr></thead>
        <tbody>
            <tr>
            <td>homepage</td>
            <td>http://www.baidu.com</td>
            </tr>
        </tbody>
        </table>
        </div>
        </template>
        
        
EOT;


    }
}